// import com.alibaba.druid.DbType;
// import com.alibaba.druid.sql.ast.SQLCommentHint;
// import com.alibaba.druid.sql.ast.SQLLimit_ptr;
// import com.alibaba.druid.sql.ast.SQLName_ptr;
// import com.alibaba.druid.sql.ast.SQLOrderBy_ptr;
// import com.alibaba.druid.sql.ast.statement.SQLDeleteStatement;
// import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.ArrayList;
// import java.util.List;

#include "MySqlDeleteStatement.h"
#include "../../../../../DbType.h"
#include "../../../../ast/SQLCommentHint.h"
#include "../../../../ast/SQLLimit.h"
#include "../../../../ast/SQLName.h"
#include "../../../../ast/SQLOrderBy.h"
#include "../../../../ast/statement/SQLTableSource.h"
#include "../../../../ast/statement/SQLWithSubqueryClause.h"
#include "../../visitor/MySqlASTVisitor.h"
#include "../../../../visitor/SQLASTVisitor.h"
#include "../../../../../utils/instanceof.h"

MySqlDeleteStatement::MySqlDeleteStatement()
    : SQLDeleteStatement(DbType_ptr(new DbType(&DbType::mysql)))
{
  hints = std::make_shared<std::list<SQLCommentHint_ptr>>();
}

SQLObject_ptr MySqlDeleteStatement::clone()
{
  SQLObject_ptr clone_tmp = MySqlDeleteStatement_ptr(new MySqlDeleteStatement());
  MySqlDeleteStatement_ptr x = std::dynamic_pointer_cast<MySqlDeleteStatement>(clone_tmp);
  // MySqlDeleteStatement x = new MySqlDeleteStatement();
  cloneTo(x);

  x->lowPriority = lowPriority;
  x->quick = quick;
  x->ignore = ignore;
  x->fulltextDictionary = fulltextDictionary;

  if (using_ != nullptr)
  {
    x->setUsing(std::dynamic_pointer_cast<SQLTableSource>(using_->clone()));
  }
  if (orderBy != nullptr)
  {
    x->setOrderBy(std::dynamic_pointer_cast<SQLOrderBy>(orderBy->clone()));
  }
  if (limit != nullptr)
  {
    x->setLimit(std::dynamic_pointer_cast<SQLLimit>(limit->clone()));
  }

  return x;
}

SQLCommentHint_list_ptr MySqlDeleteStatement::getHints()
{
  if (hints == nullptr)
  {
    hints = std::make_shared<std::list<SQLCommentHint_ptr>>();
  }
  return hints;
}

int MySqlDeleteStatement::getHintsSize()
{
  if (hints == nullptr)
  {
    return 0;
  }

  return hints->size();
}

BOOL_ptr MySqlDeleteStatement::isLowPriority()
{
  return lowPriority;
}

void MySqlDeleteStatement::setLowPriority(BOOL_ptr lowPriority)
{
  this->lowPriority = lowPriority;
}

BOOL_ptr MySqlDeleteStatement::isQuick()
{
  return quick;
}

void MySqlDeleteStatement::setQuick(BOOL_ptr quick)
{
  this->quick = quick;
}

BOOL_ptr MySqlDeleteStatement::isIgnore()
{
  return ignore;
}

void MySqlDeleteStatement::setIgnore(BOOL_ptr ignore)
{
  this->ignore = ignore;
}

SQLOrderBy_ptr MySqlDeleteStatement::getOrderBy()
{
  return orderBy;
}

void MySqlDeleteStatement::setOrderBy(SQLOrderBy_ptr orderBy)
{
  this->orderBy = orderBy;
}

SQLLimit_ptr MySqlDeleteStatement::getLimit()
{
  return limit;
}

void MySqlDeleteStatement::setLimit(SQLLimit_ptr limit)
{
  if (limit != nullptr)
  {
    limit->setParent(SharedObject(MySqlDeleteStatement));
  }
  this->limit = limit;
}

BOOL_ptr MySqlDeleteStatement::isFulltextDictionary()
{
  return fulltextDictionary;
}

void MySqlDeleteStatement::setFulltextDictionary(BOOL_ptr fulltextDictionary)
{
  this->fulltextDictionary = fulltextDictionary;
}

// @Override
void MySqlDeleteStatement::accept0(SQLASTVisitor_ptr visitor)
{
  if (instanceof<SQLASTVisitor,MySqlASTVisitor>(visitor)  )
  {
    accept0(std::dynamic_pointer_cast<MySqlASTVisitor>(visitor));
  }
  else
  {
    SQLDeleteStatement::accept0(visitor);
  }
}

void MySqlDeleteStatement::accept0(MySqlASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(MySqlDeleteStatement)))
  {
    if (with != nullptr)
    {
      with->accept(visitor);
    }

    if (tableSource != nullptr)
    {
      tableSource->accept(visitor);
    }

    if (where != nullptr)
    {
      where->accept(visitor);
    }

    if (from != nullptr)
    {
      from->accept(visitor);
    }

    if (using_ != nullptr)
    {
      using_->accept(visitor);
    }

    if (orderBy != nullptr)
    {
      orderBy->accept(visitor);
    }

    if (limit != nullptr)
    {
      limit->accept(visitor);
    }
  }

  visitor->endVisit(SharedObject(MySqlDeleteStatement));
}

BOOL_ptr MySqlDeleteStatement::isForceAllPartitions()
{
  return forceAllPartitions;
}

void MySqlDeleteStatement::setForceAllPartitions(BOOL_ptr forceAllPartitions)
{
  this->forceAllPartitions = forceAllPartitions;
}

SQLName_ptr MySqlDeleteStatement::getForcePartition()
{
  return forcePartition;
}

void MySqlDeleteStatement::setForcePartition(SQLName_ptr x)
{
  if (x != nullptr)
  {
    x->setParent(SharedObject(MySqlDeleteStatement));
  }
  this->forcePartition = x;
}
